<template>
  <swiper>
    <swiper-item v-for="item in banners" :key="item.index">
      <a :href="item.link">
        <img :src="item.image" alt="" @load="imageLoad" />
      </a>
    </swiper-item>
  </swiper>
</template>

<script>
import { Swiper, SwiperItem } from "@/components/common/swiper"; //导入轮播图组件
export default {
  name: "HomeSwiper",
  components: {
    Swiper,
    SwiperItem,
  },
  // 利用父子间传递数据
  props: {
    // 获得父组件的banners值
    banners: {
      type: Array, //定义初始类型
      default() {
        return []; //必须要有默认返回值
      },
    },
  },

  data() {
    return {
      isLoad: false,
    };
  },
  methods: {
    imageLoad() {
      if (!this.isLoad) {
        this.$emit("swpierImage"); /* 发送图片监听的请求 */
        this.isLoad = true;
      }
    },
  },
};
</script>

<style>
</style>